package com.example.controller;

import com.example.DTO.CommentDTO;
import com.example.pojo.Comment;
import com.example.pojo.Result;
import com.example.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value =  "/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;
    //添加评论(从这个接口添加的都应该是父评论)
    @RequestMapping(value = "/add")
    public Result add(@RequestBody Comment comment) {
        commentService.add(comment);
        return Result.success();
    }

    //获取所有父评论
    @RequestMapping(value = "/list")
    public Result list(Integer articleId) {
        List<CommentDTO> list = commentService.list(articleId);
        return Result.success(list);
    }
    //查看某一评论下的所有子评论
    @RequestMapping(value = "/listChild")
    public Result listChild(Integer parentId) {
        List<CommentDTO> list = commentService.listChild(parentId);
        return Result.success(list);
    }
    //回复某一条评论
    @RequestMapping(value = "/reply")
    public Result reply(@RequestBody Comment comment) {
        commentService.reply(comment);
        return Result.success();
    }


}
